//
//  RVWordDetailView.m
//  RememberVocabularies
//
//  Created by 伍银荣 on 2017/10/30.
//  Copyright © 2017年 WYR. All rights reserved.
//

#import "RVWordDetailView.h"
#import "wordsModel.h"
#import "SVProgressHUD.h"

@interface RVWordDetailView()
//单词label
@property (strong, nonatomic) IBOutlet UILabel *wordsLabel;
//读音label
@property (strong, nonatomic) IBOutlet UILabel *pronunciationLabel;
//例句labelViwe
@property (strong, nonatomic) IBOutlet UIView *sentenceLabel;
//上一个按钮
@property (strong, nonatomic) IBOutlet UIButton *lastOneBtn;
//下一个按钮
@property (strong, nonatomic) IBOutlet UIButton *nextOneBtn;
//收藏按钮
@property (strong, nonatomic) IBOutlet UIButton *collectedBtn;
//已背按钮
@property (strong, nonatomic) IBOutlet UIButton *readyReciteBtn;
@property (strong, nonatomic) IBOutlet UILabel *paraphraseLabel;

@end


@implementation RVWordDetailView

-(void)setWordsModel:(wordsModel *)wordsModel
{
    //赋值
    _wordsModel = wordsModel;
    self.wordsLabel.text = wordsModel.Word_Key;
    self.pronunciationLabel.text = [NSString stringWithFormat:@"[%@]",wordsModel.Word_Phono];
    NSArray *arr = [wordsModel.Word_Trans componentsSeparatedByString:@"；"];
    if (arr.count > 1) {
        NSMutableString *mstr = [NSMutableString new];
        for (int i=0; i<arr.count; i++) {
            [mstr appendFormat:@"%@", [NSString stringWithFormat:@"%@\n",arr[i]]];
        }
        self.paraphraseLabel.text = mstr;
    } else {
        self.paraphraseLabel.text = arr[0];
    }
    
    NSArray *transArr = [wordsModel.Word_Example componentsSeparatedByString:@"\r\n"];
    
    if (transArr.count > 1) {
        for (int i = 0; i < transArr.count; i++) {
            UILabel *lable = [[UILabel alloc]initWithFrame:CGRectMake(0, i * 50, self.frame.size.width, 50)];
            lable.text = transArr[i];
            lable.numberOfLines = 0;
            [self.sentenceLabel addSubview:lable];
        }
    } else {
        UILabel *lable = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, self.frame.size.width, 30)];
        lable.text = wordsModel.Word_Example;
        [self.sentenceLabel addSubview:lable];
    }
}

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self = [[[NSBundle mainBundle] loadNibNamed:NSStringFromClass([RVWordDetailView class]) owner:nil options:nil] firstObject];
    }
    return self;
}

//收藏按钮的点击事件
- (IBAction)collectedBtn:(id)sender {
    if ([self.delegate respondsToSelector:@selector(collectedWord:)]) {
        [self.delegate collectedWord:self.wordsModel.Word_Key];
    }
}
//已读按钮的点击事件
- (IBAction)readyReciteBtn:(id)sender {
    if ([self.delegate respondsToSelector:@selector(finishedWord:)]) {
        [self.delegate finishedWord:self.wordsModel.Word_Key];
    }
}







@end
